package com.example.mrh.zyftpt_311mrh.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.mrh.zyftpt_311mrh.R;
import com.example.mrh.zyftpt_311mrh.iface.RegisterListener;
import com.example.mrh.zyftpt_311mrh.model.RegisterModel;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{
    private TextView tv1,tvname,tvi,tvl,tvage,tvpw,tvname1,tvpw2,tvph;
    private Button b0,bp,bb;
    private EditText et1,et2,et3,et4;
    RegisterListener registerListener = new RegisterListener() {
        @Override
        public void onResponse(String msg) {
            if(msg.equals("1")){
                System.out.println("result:"+msg);
                finish();
            }else{
                System.out.println("result:"+msg);
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        init();
    }
    private void init(){
//        tv1=(TextView)findViewById(R.id.textView);
//        tvname=(TextView)findViewById(R.id.textView18);
//        tvi=(TextView)findViewById(R.id.textView24);
//        tvl=(TextView)findViewById(R.id.textView7);
//        tvage=(TextView)findViewById(R.id.textView20);
//        tvpw=(TextView)findViewById(R.id.textView12);
//        tvname1=(TextView)findViewById(R.id.textView10);
//        tvpw2=(TextView)findViewById(R.id.textView15);
//        tvph=(TextView)findViewById(R.id.textView22);
        et1=(EditText)findViewById(R.id.ResUserName);
        et2=(EditText)findViewById(R.id.RegPassword);
        et3=(EditText)findViewById(R.id.RegIphone);
//        et4=(EditText)findViewById(R.id.editText6);
        b0=(Button)findViewById(R.id.btn_register);
        bp=(Button)findViewById(R.id.btn_reset);
//        bb=(Button)findViewById(R.id.button5);

        b0.setOnClickListener(this);
        bp.setOnClickListener(this);
//        bb.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_register:
                System.out.println("注册——提交");
                RegisterModel registerModel = new RegisterModel();
                registerModel.getResult(et1.getText().toString(),
                        et2.getText().toString(),
                        et3.getText().toString(), registerListener);
                break;
            case R.id.btn_reset:
                Intent intent = new Intent(RegisterActivity.this,LoginActivity.class);
                startActivity(intent);
                break;
        }
    }
}
